package com.zhuiyun.educations.api.collect.service.impl;

import com.zhuiyun.educations.api.collect.entity.CollectEntity;
import com.zhuiyun.educations.api.collect.entity.DTO.CollectDTO;
import com.zhuiyun.educations.api.collect.mapper.CollectMapper;
import com.zhuiyun.educations.api.collect.service.CollectService;
import com.zhuiyun.educations.api.course.entity.Course;
import com.zhuiyun.educations.api.course.entity.DTO.CourseDTO;
import com.zhuiyun.educations.common.response.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CollectServiceImpl
 * @Description TODO
 * @Author cjl
 * @Date 2023/6/26 9:25
 **/
@Service
public class CollectServiceImpl implements CollectService {

    @Autowired
    CollectMapper collectMapper;

    /**
     * @Author cjl
     * @Description 查寻登录用户的收藏（视频 文章 直播）
     * @Date 2023/6/26 14:41
     * @Return com.zhuiyun.educations.common.response.CommonResult
     * @param userId
     * @param courseType
     */
    @Override
    public CommonResult selectCollectJoinCourse(Integer userId, Integer courseType) {
        List<CollectDTO>  list = collectMapper.selectCollectJoinCourse(userId,courseType);
        return CommonResult.ok(list);
    }

    @Override
    public CommonResult updateCollectDelFlagByUserId(Integer collectId) {
        CollectEntity collectEntity = new CollectEntity();
        collectEntity.setId(collectId);
        collectEntity.setDelFlag(1);
        int i = collectMapper.updateByPrimaryKeySelective(collectEntity);
        if (i!=0){
            return CommonResult.ok("恭喜你，修改成功！");
        }else {
            return CommonResult.error(1000,"修改用户名失败!!!");
        }
    }
}
